<?php
/**
 * @Author: Xu Liu email:2867557054@qq.com
 * @Date:   2016-12-15 13:31:33
 * @Last Modified by:   Xu Liu
 * @Last Modified time: 2018-05-17 12:57:21
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denid');
}
class table_jamesonread_books extends discuz_table
{
    public function __construct()
    {
        $this->_table         = 'jamesonread_books';
        $this->_pk            = 'book_id';
        $this->_pre_cache_key = 'jamesonreadbooks_';
        $this->_cache_ttl     = 300;
        parent::__construct();
    }
    public function fetchAllInfoById($book_id, $uid = 0)
    {
        $cacheid = "bookinfo-".$book_id."-".$uid;
        if($cache = $this->fetch_cache($cacheid)){
            return $cache;
        }
        $books   = DB::fetch_first('SELECT b.*,c.category_name FROM %t as b LEFT JOIN %t AS c ON b.category_id=c.category_id  WHERE b.book_id=%d', array($this->_table, 'jamesonread_categorys', $book_id));
        if(!$books){
            return false;
        }
        $fenjuan = (array) DB::fetch_all('SELECT * FROM %t WHERE book_id=%d ORDER BY order_num ASC', array('jamesonread_fenjuan', $book_id), 'j_id');
        if ($fenjuan) {
            $nofor = DB::fetch_all('SELECT * FROM %t WHERE ' . DB::field('book_id', $book_id) . ' ORDER BY j_id, zhangjie', array('jamesonread_colums'));
            $books['hascol'] = intval(count($nofor));
            foreach ($nofor as $key => $value) {
                if ($fenjuan[$value['j_id']]) {
                    $fenjuan[$value['j_id']]['colums'][$value['colum_id']] = $value;
                }
            }
            $first = 0;
            foreach ($fenjuan as $j) {
                if ($first < 1) {
                    $firstcol = current($j['colums']);
                    $books['firsttid']   = $firstcol['tid'];
                    $books['firstpid']   = $firstcol['pid'];
                    $books['firstprice'] = $firstcol['price'];
                    $first++;
                    break;
                }
            }
        }
        $books['fenjuan']     = $fenjuan;
        $this->store_cache($cacheid,$books);
        return $books;
    }

    public function fetch_name($book_id)
    {
        $cacheid = 'fetch_name';
        if ($cache = $this->fetch_cache($cacheid)) {
            return $cache;
        }
        $bookname = DB::result_first('SELECT book_name FROM %t WHERE book_id=%d', array($this->_table, $book_id));
        $this->store_cache($cacheid, $bookname);
        return $bookname;
    }
    public function fetch_category($book_id)
    {
        $cacheid = 'fetch_category';
        if ($cache = $this->fetch_cache($cacheid)) {
            return $cache;
        }
        $data = DB::fetch_first('SELECT parent_id AS pid,category_id AS cid FROM %t WHERE book_id=%d', array($this->_table, $book_id));
        $this->store_cache($cacheid,$data);
        return $data;
    }
    // 当前用户发布的所有在架图书
    public function fetch_by_uid($uid, $start, $size, $status = 1, $admin = 0)
    {
        $con = array('uid', '=', $uid);
        if ($uid == 1 && $admin == 1) {
            $con = array();
        }
        return $this->fetchAll_by_field($con, array(), array(), $start, $size, $status);
    }
    public function count_by_uid($uid, $status = 1, $admin = 0)
    {
        if ($uid == 1 && $admin == 1) {
            return $this->count_by_con(array(), $status);
        }
        return $this->count_by_con(array('uid', '=', $uid), $status);
    }
    public function count_by_author($author, $status = 1)
    {
        return $this->count_by_con(array('author', '=', $author), $status);
    }
    public function fetch_by_author($author, $start, $size)
    {
        return $this->fetchAll_by_field(array('author', '=', $author), array(), array(), $start, $size, 1);
    }
    public function counttop_by_uid($uid)
    {
        return (int) DB::result_first('SELECT count(book_id) FROM %t WHERE uid=%d AND ' . DB::field('is_top', '0', '>'), array($this->_table, $uid));
    }
    public function count_online($status = 1, $field = null, $value = null)
    {
        $contind = array();
        if ($field && $value) {
            $contind = array($field, '=', $value);
        }
        return $this->count_by_con($contind, $status);
    }
    public function fetch_online($start, $size, $status = 1)
    {
        return DB::fetch_all('SELECT b.book_name,b.book_id,b.zishu,b.category_id,b.favores,b.scores,b.dpcount,b.ordernum,b.uid,b.views,b.author,b.addtime,b.is_top,b.is_jingxuan,b.plan,b.bookmoney,b.bindfid,b.shuxing,b.hascol,c.username,ca.parent_id FROM %t AS b LEFT JOIN %t AS c ON b.uid=c.uid INNER JOIN %t AS ca ON b.category_id=ca.category_id WHERE b.status=%d ORDER BY b.addtime DESC LIMIT %d,%d', array($this->_table, 'common_member', 'jamesonread_categorys', $status, $start, $size));

    }
    /*
    $con=array($field,$glue, $contind),
    $cid = array($parent_id,$category_id),
    $order=array($field,$desc),
    $start,
    $size
     */
    public function fetchAll_by_field($con = array(), $cid = array(), $order = array(), $start = 0, $size = 30, $status = 1)
    {
        if ($con[0] == 'sell') {
            return $this->fetch_sell_buypid($cid[0], $start, $size);
        }
        $childcate = $field = '';
        $thecid    = $cid[0] ? $cid[0] : ($cid[1] ? $cid[1] : 0);
        if ($thecid) {
            $childcate = "  (b." . trim(DB::field('category_id', $thecid)) . ' OR b.' . trim(DB::field('parent_id', $thecid)) . ") AND ";
        }
        if ($con && count($con) == 3) {
            $field = ' b.' . trim(DB::field($con[0], $con[2], $con[1])) . " AND ";
        }
        $orderstr = $order ? trim(implode(',', $order), ',') : ' b.addtime DESC';
        $data     = DB::fetch_all('SELECT b.*,c.category_name FROM %t as b INNER JOIN ' . DB::table('jamesonread_categorys') . ' as c ON b.category_id=c.category_id WHERE ' . $field . $childcate . '  b.status=%d ORDER BY ' . $orderstr . ' LIMIT %d,%d', array($this->_table, $status, $start, $size));
        return $data;
    }
    public function count_by_con($con = array(), $status = 1)
    {
        if ($con[0] == 'sell') {
            return DB::result_first('SELECT COUNT(id) FROM ' . DB::table('jamesonread_buybooks') . ' GROUP BY book_id ');
        } else if ($con && count($con) == 3) {
            $where = DB::field($con[0], $con[2], $con[1]);
            if ($con[0] == 'category_id') {
                $where = ' (' . DB::field('category_id', $con[2]) . ' OR ' . DB::field('parent_id', $con[2]) . ')';
            }
            return DB::result_first('SELECT COUNT(book_id) FROM ' . DB::table($this->_table) . ' WHERE ' . DB::field('status', $status) . ' AND ' . $where);
        } else {
            return DB::result_first('SELECT COUNT(book_id) FROM ' . DB::table($this->_table) . ' WHERE ' . DB::field('status', $status));
        }
    }
    public function fetch_sell_buypid($parent_id, $start, $size)
    {
        $bookids = DB::fetch_all('SELECT book_id,sum(price) as total FROM %t group by book_id ORDER BY total DESC LIMIT %d,%d', array('jamesonread_buytids', $start, $size), 'book_id');
        if(!$bookids){
            return array();
        }
        $books   = DB::fetch_all('SELECT * FROM %t WHERE ' . DB::field('book_id', array_keys($bookids)), array('jamesonread_books'));
        foreach ($books as $key => $value) {
            $books[$key]['total'] = $bookids[$value['book_id']]['total'];
        }
        return $books;
    }
    public function all()
    {
        return DB::fetch_all('SELECT book_id,book_name FROM %t WHERE status=%d', array($this->_table, 1));
    }
    public function fetch_update($start, $size = 20, $parent_id = 0)
    {
        $lei = '';
        if($parent_id){
            $lei = C::t('#jameson_read#jamesonread_categorys')->fetch_all_parent($parent_id);
            $lei = $lei?' AND '.DB::field('category',array_keys($lei)):''; 
        }
        $cols = DB::fetch_all('SELECT tid,pid,subject,book_id,category_id,zhangjie,price,addtime FROM %t WHERE  '.DB::field('addtime',TIMESTAMP-604800,'>').$lei.'  GROUP BY book_id ORDER BY addtime DESC,zhangjie DESC LIMIT %d,%d',array('jamesonread_colums',0,$size),'book_id');
        if(!$cols){
            return array();
        }
        $bks  = DB::fetch_all('SELECT book_name,book_id,author,parent_id,image FROM %t WHERE '.DB::field('book_id',array_keys($cols)),array($this->_table),'book_id');
        if(!$bks){
            return array();
        }
        foreach ($cols as $key => $value) {
            $cols[$key]['book_name'] = $bks[$key]['book_name'];
            $cols[$key]['author'] = $bks[$key]['author'];
            $cols[$key]['parent_id'] = $bks[$key]['parent_id'];
            $cols[$key]['image'] = $bks[$key]['image'];
        }
        return $cols;
    }
    public function fetch_end($nums = 15)
    {
        return $this->fetchAll_by_field(array('plan', '>', 0), array(), array('views desc', 'addtime desc'), 0, 30);

    }
    public function fetch_books_byfid($fid, $type = 'bindfid')
    {
        return $this->fetchAll_by_field(array($type, '=', $fid), array(), array(), 0, 30);

    }
    public function count_search($keyword, $type = '', $byauthor = '')
    {
        $keyword = preg_replace("/(%|_)+/i", '\\\\' . "\\1", daddslashes($keyword));
        $contind = DB::field('book_name', '%' . $keyword . '%', 'like') . ' OR ' . DB::field('author', '%' . $keyword . '%', 'like') . ' OR ' . DB::field('shuxing', '%' . $keyword . '%', 'like');
        return (int) DB::result_first("SELECT count(book_id) FROM " . DB::table($this->_table) . " WHERE (" . $contind.") and ".DB::field('status',1));
    }
    public function fetch_search($keyword, $type = '', $start = 0, $size = 30, $byauthor = '')
    {
        $keyword = preg_replace("/(%|_)+/i", '\\\\' . "\\1", daddslashes($keyword));
        $contind = DB::field('book_name', '%' . $keyword . '%', 'like') . ' OR ' . DB::field('author', '%' . $keyword . '%', 'like') . ' OR ' . DB::field('shuxing', '%' . $keyword . '%', 'like');
        if($type=='same'){
            $len = mb_strlen($keyword);
            $contind .= ' OR ' .DB::field('book_name','%'.mb_substr($keyword,0,floor($len/2)).'%','like');
            $contind .= ' OR ' .DB::field('book_name','%'.mb_substr($keyword,0,$len>2?2:1).'%','like');
        }
        return (array) DB::fetch_all("SELECT b.*,ct.category_name FROM " . DB::table($this->_table) . " AS b INNER JOIN " . DB::table('jamesonread_categorys') . " AS ct ON b.category_id=ct.category_id WHERE ($contind) AND ".DB::field('status',1)."  LIMIT " . $start . "," . $size);
    }

    public function count_search_at_author($uid, $name)
    {
        $name  = preg_replace("/(%|_)+/i", '\\\\' . "\\1", daddslashes($name));
        $where = DB::field('status', 1) . ' AND (' . DB::field('book_name', '%' . $name . '%', 'like') . ' OR ' . DB::field('author', '%' . $name . '%', 'like') . ')';
        if ($uid != 1) {
            $where .= ' AND ' . DB::field('uid', $uid);
        }
        return DB::result_first('SELECT count(book_id) FROM ' . DB::table($this->_table) . ' WHERE ' . $where);
    }
    public function fetch_search_at_author($uid, $name, $start, $size)
    {
        $name  = preg_replace("/(%|_)+/i", '\\\\' . "\\1", daddslashes($name));
        $where = '(' . DB::field('book_name', '%' . $name . '%', 'like') . ' OR ' . DB::field('author', '%' . $name . '%', 'like') . ') ';
        if (1 != $uid) {
            $where .= " AND b.uid='" . $uid . "' AND b.status='1'";
        }
        $data = DB::fetch_all('SELECT b.*,c.username FROM ' . DB::table($this->_table) . ' AS b INNER JOIN ' . DB::table('common_member') . ' AS c ON b.uid=c.uid WHERE ' . $where . '  ' . DB::limit($start, $size));
        return $data;
    }
    // add views
    public function addviews($book_id)
    {
        DB::query('UPDATE ' . DB::table($this->_table) . ' SET ' . DB::field('views', 1, '+') . ' WHERE book_id=' . intval($book_id));
    }
    // 符合条件的图书共有多少
    public function count_shaixuan($data)
    {
        $count = (int) DB::result_first('SELECT count(book_id) FROM %t WHERE status=%d ' . $this->field_string($data) . '  ORDER BY is_top DESC, addtime DESC ', array($this->_table, 1));
        return $count;
    }
    // 获取符合条件的图书记录
    public function fetch_shaixuan($data, $start, $size)
    {
        
        $data = DB::fetch_all('SELECT b.*,c.category_name FROM %t AS b INNER JOIN %t AS c ON b.category_id=c.category_id WHERE b.status=%d ' . $this->field_string($data, 'b') . ' ORDER BY  b.addtime DESC LIMIT %d,%d', array($this->_table, 'jamesonread_categorys', 1, $start, $size));
        if ($data) {
            return $data;
        } else {
            return array();
        }
    }
    // 条件组装
    protected function field_string($data, $table = '')
    {
        if (!$data || !is_array($data)) {
            return '';
        }
        $contid = array();
        $where  = '';
        $table  = $table ? trim($table) . '.' : '';
        foreach ($data as $key => $value) {
            // 按售价
            if ($key == 'bookmoney') {
                if ($value) {
                    $contid[] = $table . trim(DB::field('bookmoney', 0, '>'));
                } else {
                    $contid[] = $table . trim(DB::field("bookmoney", 0));
                }
            } else if ($key == 'zishu') {
                // 字数
                if ($value == 10000001) {
                    // 大于1000 0000
                    $contid[] = $table . trim(DB::field("zishu", $value, '>='));
                } else if ($value) {
                    $contid[] = $table . trim(DB::field("zishu", $value, '<'));
                }
            } else if ($key == 'plan') {
                if ($value > 0) {
                    $contid[] = $table . trim(DB::field("plan", 0, '>'));
                } else {
                    $contid[] = $table . trim(DB::field("plan", 1, '<'));
                }
            } else if ($key == 'category_id') {
                $contid[] = '  (' . $table . trim(DB::field('parent_id', $value)) . ' OR ' . $table . trim(DB::field('category_id', $value)) . ') ';
            } else {
                $contid[] = $table . trim(DB::field($key, $value));
            }
        }
        if ($contid) {
            $where = ' AND ' . implode(" AND ", $contid);
        }
        return $where;
    }
    public function fetch_by_newauthor($parent_id, $size)
    {
        $cacheid = 'fetch_by_newauthor-'.$parent_id.'-'.$size;
        if ($cache = $this->fetch_cache($cacheid)) {
            return $cache;
        }
        $cate = $parent_id ? ' AND b.' . trim(DB::field('parent_id', $parent_id)) : '';
        $data = DB::fetch_all('SELECT b.*,c.uid,c.regdate,a.author_id FROM %t as b INNER JOIN ' . DB::table('common_member') . ' as c ON b.uid=c.uid INNER JOIN ' . DB::table('jamesonread_authors') . ' as a ON b.uid=a.author_id WHERE b.status=%d ' . $cate . ' ORDER BY  c.regdate DESC,b.addtime DESC LIMIT %d', array($this->_table, 1, $size));
        if ($data) {
            $this->store_cache($cacheid, $data);
        }
        return $data;
    }
    public function fetch_tuijian($force = 'no')
    {
        if ($cache = $this->fetch_cache('fetch_tuijian')) {
            return $cache;
        }
        $size = 30;
        $data = $new = array();
        $data = DB::fetch_all("SELECT * FROM %t  ORDER BY parent_id ASC,ordernum ASC", array('jamesonread_categorys'), 'category_id');
        if (!$data) {
            return $data;
        }
        foreach ($data as $key => $value) {
            if ($value['parent_id']) {
                $new[$value['parent_id']]['sub_category_id'][] = $key;
                $new[$value['parent_id']]['sub'][$key]         = $value;
            } else {
                $new[$key]            = $value;
            }
        }
        $pid1 = current($new);
        if($pid1 && $pid1['category_id']){
            $new[$pid1['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid1['category_id']) .' AND '.DB::field('status', 0,'>') . ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid1['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid1['category_id']) .' AND '.DB::field('status', 0,'>').  ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid2 = next($new);
        if($pid2 && $pid2['category_id']){
            $new[$pid2['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid2['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid2['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid2['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid3 = next($new);
        if($pid3 && $pid3['category_id']){
            $new[$pid3['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid3['category_id']) .' AND '.DB::field('status', 0,'>').' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid3['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid3['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid4 = next($new);
        if($pid4 && $pid4['category_id']){
            $new[$pid4['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid4['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid4['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid4['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid5 = next($new);
        if($pid5 && $pid5['category_id']){
            $new[$pid5['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid5['category_id']) .' AND '.DB::field('status', 0,'>').  ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid5['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid5['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid6 = next($new);
        if($pid6 && $pid6['category_id']){
            $new[$pid6['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid6['category_id']) .' AND '.DB::field('status', 0,'>').' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid6['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid6['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid7 = next($new);
        if($pid7 && $pid7['category_id']){
            $new[$pid7['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid7['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid7['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid7['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid8 = next($new);
        if($pid8 && $pid8['category_id']){
            $new[$pid8['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid8['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid8['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid8['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid9 = next($new);
        if($pid9 && $pid9['category_id']){
            $new[$pid9['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid9['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid9['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid9['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $pid10 = next($new);
        if($pid10 && $pid10['category_id']){
            $new[$pid10['category_id']]['tuijian'] = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid10['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('is_top', 'desc') . ',addtime desc LIMIT ' . $size);
            $new[$pid10['category_id']]['yuedu']   = DB::fetch_all('SELECT * FROM ' . DB::table('jamesonread_books') . ' WHERE ' . DB::field('parent_id', $pid10['category_id']) .' AND '.DB::field('status', 0,'>'). ' ORDER BY ' . DB::order('views', 'desc') . ',addtime desc LIMIT ' . $size);
        }
        $this->store_cache('fetch_tuijian',$new);
        return $new;
    }
    public function fetch_paihang($focre = 'no')
    {
        if ($cache = $this->fetch_cache('fetch_paihang')) {
            return $cache;
        }
        global $_G;
        $size                 = 30;
        $paihangbang          = array();
        $paihangbang['yuedu'] = $this->fetchAll_by_field(array(), array(), array(
            ' views desc ', ' addtime desc ',
        ), 0, $size);
        $paihangbang['haoping'] = $this->fetchAll_by_field(array(), array(), array(
            ' scores desc ', ' dpcount asc ', ' addtime desc ',
        ), 0, $size);
        $paihangbang['shoucang'] = $this->fetchAll_by_field(array(), array(), array(
            ' favores desc ', ' addtime desc ',
        ), 0, $size);
        $paihangbang['zuixin'] = $this->fetchAll_by_field(array(), array(), array(
            ' addtime desc ',
        ), 0, $size);
        $paihangbang['tuijian'] = $this->fetchAll_by_field(array(), array(), array(
            ' is_top desc ', ' addtime desc ',
        ), 0, $size);
        if($_G['cache']['plugin']['jameson_read']['enableshupiao']){
            $paihangbang['yuepiao'] = $this->fetchAll_by_field(array('yuepiao', '>', 0), array(), array(
                ' yuepiao desc ', ' addtime desc ',
            ), 0, $size);
            $paihangbang['tuijianpiao'] = $this->fetchAll_by_field(array('tuijianpiao', '>', 0), array(), array(
                ' tuijianpiao desc ', ' addtime desc ',
            ), 0, $size);
            $paihangbang['cuigengpiao'] = $this->fetchAll_by_field(array('cuigengpiao', '>', 0), array(), array(
                ' cuigengpiao desc ', ' addtime desc ',
            ), 0, $size);
        }
        $paihangbang['sell']   = $this->fetch_sell_buypid(0, 0, $size);
        $paihangbang['update'] = C::t('#jameson_read#jamesonread_update')->fetch_update($size);
        $paihangbang['end']    = $this->fetch_end($size);
        $this->store_cache('fetch_paihang',$paihangbang);
        return $paihangbang;
    }
}
